<template>
	<view class="content">
		<u-navbar title="发货" :autoBack="true">
		</u-navbar>
		<view class="top add">
			<text class="c2" style="font-weight: 500;">当前发货方式为自取，请直接点击“发货”确认发货</text>
			<view class="c1">备注</view>
			<view class="c2">
				<u--input v-model='info.note' placeholder="请输入" :customStyle="{padding: '0 32rpx'}">
				</u--input>
			</view>
		</view>
		<view class="but">
			<view class="s2" @click="onSend()">
				<text>发 货</text>
			</view>
		</view>

	</view>
</template>

<script>
	import conf from '@/common/config.js';
	export default {
		data() {
			return {
				id: 0,
				activityid: 0,
				info: {},
				fileList1: [],
			};
		},
		onLoad(options) {
			this.id = options.id
			this.activityid = options.activityid || 0
			this.getInfo();
		},
		onShow() {

		},
		methods: {
			getInfo() {
				this.$API.getShopOrder({
					id: this.id
				}).then(res => {
					this.info = res.data;
					this.fileList1 = res.data.send_out_images_url;
				});
			},
			copyText(text) {
				uni.setClipboardData({
					data: text,
					success: function() {
						uni.showToast({
							title: '复制成功',
							icon: 'success',
							duration: 2000
						});
					}
				});
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				// console.log('lists', lists, this.fileList1)
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				let host_url = conf.url_config + '/api/common/upload';

				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: host_url,
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						header: {
							Token: this.vuex_token
						},
						success: (res) => {
							let data = JSON.parse(res.data);
							setTimeout(() => {
								resolve(data.data.url)
							}, 1000)
						}
					});
				})
			},
			onSend() {
				let that = this
				let data = {
					id: this.info.id,
					note: this.info.note,
				};
				this.$API.activitySendOut(data).then(res => {
					uni.redirectTo({
						url: '/pages/activity/order?id=' + this.activityid
					})
				});
			}
		}
	}
</script>

<style lang="scss">
	.content {
		width: 670rpx;
		margin: 0 auto;
	}

	.top {
		@include flex(column);
		width: 590rpx;
		padding: 52rpx 40rpx;
		background-color: #fff;
		border-radius: 48rpx;
		margin: 50rpx auto 0 auto;

		.title {
			height: 48rpx;
			font-size: 40rpx;
			font-weight: bold;
			color: #0A1629;
			line-height: 48rpx;
		}

		.s1 {
			@include flex;
			position: relative;
			align-content: center;
			margin-top: 46rpx;

			.c1 {
				width: 100rpx;
				font-size: 28rpx;
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: 400;
				color: #91929E;
				line-height: 32rpx;
				margin-right: 20rpx;
				text-align: right;
			}

			.c2 {
				width: 400rpx;
				font-size: 30rpx;
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: 400;
				color: #0A1629;
				line-height: 32rpx;
				overflow: hidden;
			}

			.c3 {
				height: 32rpx;
				font-size: 24rpx;
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: 500;
				color: #7677EB;
				line-height: 32rpx;
			}
		}

		.bottom {
			height: 36rpx;
			font-size: 30rpx;
			font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
			font-weight: 400;
			color: #7677EB;
			line-height: 36rpx;
			text-align: center;
			margin-top: 48rpx;
		}
	}

	.add {
		width: 566rpx;
		padding: 52rpx;
		background-color: #fff;
		border-radius: 48rpx;
		margin-top: 52rpx;

		.s1 {
			width: 100%;
			height: 34rpx;
			font-size: 28rpx;
			font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
			font-weight: 600;
			color: #7677EB;
			line-height: 34rpx;
			text-align: center;
		}

		.title {
			width: 100%;
			height: 52rpx;
			font-size: 36rpx;
			font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
			font-weight: 600;
			color: #110202;
			line-height: 52rpx;
			text-align: center;
			margin-top: 16rpx;
		}

		.c1 {
			height: 28rpx;
			font-size: 28rpx;
			font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
			font-weight: 400;
			color: #7D8592;
			line-height: 28rpx;
			margin-top: 56rpx;
		}

		.c2 {
			width: 566rpx;
			margin-top: 40rpx;

			/deep/ .u-input {
				height: 98rpx;
				border-radius: 28rpx;
			}
		}
	}

	.but {
		@include flex;
		margin-top: 60rpx;
		margin-bottom: 60rpx;

		.s2 {
			width: 290rpx;
			height: 96rpx;
			background: #7677EB;
			box-shadow: 0 12rpx 24rpx 0 rgba(63, 140, 255, 0.2637);
			border-radius: 28rpx;
			margin: 0 auto 80rpx;
			text-align: center;

			text {
				font-size: 30rpx;
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 96rpx;
			}
		}
	}
</style>